package com.itheima.jobs;



import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.OrderSettingService;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Component
public class ClearOrderSettingJob {

    @Reference
    private OrderSettingService orderSettingService;

    public void clearOrderSetting() {
        //获取上个月的最后一天，清理 <= monthEnd的数据
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        Date time = calendar.getTime();
        String month = new SimpleDateFormat("yyyy-MM").format(time);
        String monthEnd = month + "-31";
        System.out.println(monthEnd);
        orderSettingService.clearByMonth(monthEnd);
    }

}
